<?php
namespace api\modules\user\controllers;

use Yii;
use yii\base\InvalidParamException;
use yii\web\BadRequestHttpException;

use yii\filters\VerbFilter;
use yii\filters\AccessControl;

use base\YiiMobo;

/**
 * Site controller
 */
class IndexController extends \submodule\base\BaseSubmoduleApiController
{
	public $moduleid = 'user';
	
	public function init(){
	    parent::init();
	}
	

    public function actionIndex(){
		$this->apiList();
	}
	
	
	public function actionView(){
		$this->apiView();
	}
	
	
	public function actionCreate(){
		$this->apiCreate();
	}
	
	public function actionUpdate(){
		$this->apiUpdate();
	}
	
	public function actionLogin(){
		$this->requests = $_GET;
		
		$bindparam = $this->isRequired(['mobileno', 'password']);
		unset($bindparam[':password']);
		$sql = "SELECT `userid`,`username`,`nikename`,`password` FROM {$this->submodel->tablename} where `mobileno` = :mobileno";
		$data['results'] = $this->query($sql, $bindparam, 'one', false);
		if (!$data['results']){
			self::errmsg('手机号不存在');
		}else if($data['results']['password'] != $this->requests['password']){
			self::errmsg('密码不正确');
		}
		unset($data['results']['password']);
		
		self::echojson($data);
		
	}
}
